Skip to main content

Write data to pasteboard (pasteboard.write)

Declaration​

pasteboard.write(data [, uti ])
pasteboard.write(item [, options ])
pasteboard.write(items [, options ])

Parameters​

  • data
    String. The content to write to the system pasteboard.
    Table. A pasteboard item whose keys are UTIs and values are string data. (supported since version 20260428)
    Table. A list of pasteboard items. (supported since version 20260428)

  • uti
    String, optional. Uniform Type Identifiers. Default: "public.utf8-plain-text".

  • options
    Table, optional. (supported since version 20260428)
    local_only: Boolean. Keep the content local to this device. Supported on iOS 10 and later.
    expiration_date: Number. Unix timestamp in seconds. Supported on iOS 10 and later.

    Pasteboard item structure
    {
    ["public.utf8-plain-text"] = "plain text",
    ["public.rtf"] = "RTF data",
    ["public.html"] = "HTML data",
    ["public.png"] = "PNG binary data",
    ...
    }

Returns​

  • success
    Boolean. Returns true when writing succeeds; otherwise returns false.

Description​

Write content into the system pasteboard.
When item or items is provided, multiple representations are written to the same pasteboard item. iOS 9 ignores options.

Example​

pasteboard.write("hello") -- Write the text "hello" to the pasteboard
--
pasteboard.write(screen.image():png_data(), 'public.png') -- Write a screenshot to the pasteboard
--
pasteboard.write([[{\rtf1\ansi\deff0
{\fonttbl{\f0 Helvetica;}}
{\colortbl;\red255\green0\blue0;}
\f0\fs32 normal {\b bold} {\i italic} \cf1 red\cf0\par
\u20320?\u22909?
}]], "public.rtf") -- Write RTF rich text to the pasteboard

-- Version 20260428 and later support writing multiple representations to one item
pasteboard.write({
["public.utf8-plain-text"] = "normal bold italic red\nHello",
["public.rtf"] = [[{\rtf1\ansi\deff0
{\fonttbl{\f0 Helvetica;}}
{\colortbl;\red255\green0\blue0;}
\f0\fs32 normal {\b bold} {\i italic} \cf1 red\cf0\par
Hello
}]],
["public.html"] = [[<p>normal <b>bold</b> <i>italic</i> <span style="color:red">red</span><br>Hello</p>]],
}, {
local_only = true,
expiration_date = os.time() + 3600,
})

Note: Uses screen.image